package com.dant.utils
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    import flash.geom.Matrix;
    
    import mx.controls.Image;
    
    public class SnapshotUtil
    {
        public function SnapshotUtil()
        {
        }

        protected static function getBitmapData( target : DisplayObject ) : BitmapData
        {
            var bd : BitmapData = new BitmapData( target.width, target.height );
            var m : Matrix = new Matrix();
            bd.draw( target, m );
            return bd;
        }

        public static function takeSnapshot(component:DisplayObject):Image 
        {
            var bd : BitmapData = getBitmapData( DisplayObject( component ) );            
            var snap:Image = new Image();
            var bm:Bitmap = new Bitmap(bd);
            bm.smoothing = true;
            snap.source = bm;
            return (snap);
        }

    }
}